// function onClick_alert_id(obj,path) {
//     var trId = obj.parentNode.parentNode.id;
//     var trObj = document.getElementById(trId);
//     var employee_id=document.getElementById(trId).getElementsByTagName("td")[0].innerHTML;
//     $.ajax({
//         //几个参数需要注意一下
//         type: "POST",//方法类型
//         data: {employee_id:employee_id},
//         dataType: "json",//预期服务器返回的数据类型
//         url: path+"/Action/Action_EmployeeAction_get_id" ,//url
//         success: function (result) {
//             var employee=result;
//             alert_id(employee)
//         },
//         error : function() {
// //                  alert("异常！");
//         }
//     });
// }
function onClick_DiningReceiptService_delete_id(obj,path) {
    var trId = obj.parentNode.parentNode.id;
    var trObj = document.getElementById(trId);
    var diningReceipt_id=document.getElementById(trId).getElementsByTagName("td")[0].innerHTML;
    $.ajax({
        //几个参数需要注意一下
        type: "POST",//方法类型
        data: {diningReceipt_id:diningReceipt_id},
        dataType: "json",//预期服务器返回的数据类型
        url: path+"/Action/Action_DiningReceiptAction_delete" ,//url
        success: function (result) {
            document.getElementById("tb").removeChild(trObj);
        },
        error : function() {
//                  alert("异常！");
        }
    });
}
function delete_id(trId) {
    var trObj = document.getElementById(trId);
    document.getElementById("tb").removeChild(trObj);
}
//flag_type_diningReceipt:0,1,2  0:index 1:sum_index 2:sum_index2

function getDataRow_DiningReceipt(diningReceipt,flag_admin,flag_type_diningReceipt){
    var row = document.createElement('tr'); //创建行
    if (flag_type_diningReceipt==1){
        var cell = document.createElement('td');//创建第三列job
        cell.innerHTML = diningReceipt.dining_company;
        row.appendChild(cell);
    }
    else if(flag_type_diningReceipt==2){

    }
    else if(flag_type_diningReceipt==0){
        if (flag_admin==true){
            //如果admin，显示dining_id，employee_account
            var cell = document.createElement('td'); //创建第一列id
            cell.innerHTML = diningReceipt.dining_id; //填充数据
            row.appendChild(cell); //加入行  ，下面类似

            var cell = document.createElement('td');//创建第二列name
            cell.innerHTML = diningReceipt.employee_account;
            row.appendChild(cell);

        }
        var cell = document.createElement('td');//创建第三列job
        cell.innerHTML = diningReceipt.dining_company;
        row.appendChild(cell);
    }

    var cell = document.createElement('td');//创建第三列job
    cell.innerHTML = diningReceipt.dining_time;
    row.appendChild(cell);

    var cell = document.createElement('td');//创建第三列job
    cell.innerHTML = diningReceipt.dining_type;
    row.appendChild(cell);


    var cell = document.createElement('td');//创建第三列job
    cell.innerHTML = diningReceipt.leadership_number;
    row.appendChild(cell);

    var cell = document.createElement('td');//创建第三列job
    cell.innerHTML = diningReceipt.employee_number;
    row.appendChild(cell);

    if(flag_type_diningReceipt==0){
        var cell = document.createElement('td');//创建第三列job
        cell.innerHTML = diningReceipt.note;
        row.appendChild(cell);
    }

    //到这里，json中的数据已经添加到表格中，下面为每行末尾添加删除按钮

    // var delCell = document.createElement('td');//创建第四列，操作列
    // row.appendChild(delCell);
    // var btnDel = document.createElement('input'); //创建一个input控件
    // btnDel.setAttribute('type','button'); //type="button"
    // btnDel.setAttribute('value','删除');

    // //删除操作
    // btnDel.onclick=function(){
    //     if(confirm("确定删除这一行嘛？")){
    //         //找到按钮所在行的节点，然后删掉这一行
    //         this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);
    //         //btnDel - td - tr - tbody - 删除(tr)
    //         //刷新网页还原。实际操作中，还要删除数据库中数据，实现真正删除
    //     }
    // };
    // delCell.appendChild(btnDel);  //把删除按钮加入td，别忘了

    return row; //返回tr数据
}
var falg_allData=false;
function onclick_falg_allData(path,flag_admin,flag_type_diningReceipt) {
    var button_falg_allData_value="当前仅显示"+numberData_perPage+"条数据";
    if (falg_allData){
        button_falg_allData_value="当前显示所有数据";
    }
    else {
        button_falg_allData_value="当前仅显示"+numberData_perPage+"条数据";
    }
    falg_allData=!falg_allData;
    $('#button_falg_allData').val(button_falg_allData_value);
    getDiningReceipts(path,flag_admin,flag_type_diningReceipt);
}
//flag_admin:是否是admin
//flag_type_diningReceipt:0,1,2  0:index 1:sum_index 2:sum_index2
var list_diningReceipt=null;
var list_diningReceipt_filter=null;
var index_page=1;
var number_page=1;
var max_number_page=999999;
var numberData_perPage=15;
function getOnePage_DiningReceipts(flag_admin,flag_type_diningReceipt,index_page){
    this.index_page=index_page;           
    document.getElementById("tb").innerHTML='';
    var lowerlimit_numberData=(index_page-1)*numberData_perPage;
    var uplimit_numberData=index_page*numberData_perPage;
    if (uplimit_numberData>list_diningReceipt_filter.length) {
        uplimit_numberData=list_diningReceipt_filter.length;
    }
    for (var index_com = lowerlimit_numberData; index_com < uplimit_numberData; index_com++) {
            var trow = getDataRow_DiningReceipt(list_diningReceipt_filter[index_com],flag_admin,flag_type_diningReceipt); //定义一个方法,返回tr数据
            document.getElementById("tb").appendChild(trow);
    }
}
function getPages(flag_admin,flag_type_diningReceipt){
    document.getElementById("tb").innerHTML='';
    filterDiningReceipt_dining_company();
    filterDiningReceipt_dining_time();
    filterDiningReceipt_dining_type();
     $('#div_data_navagation').html("");
    number_page=Math.floor(list_diningReceipt_filter.length/numberData_perPage)+1;
    getOnePage_DiningReceipts(flag_admin,flag_type_diningReceipt,index_page);
    var div_data_navagation_html1='<button id="btn_previousPage">anterior</button>';
    $('#div_data_navagation').append(div_data_navagation_html1);


    for(var i=0;i<number_page;i++){
        var btn_indexPage = document.createElement('button'); //创建一个input控件
        btn_indexPage.setAttribute('id','btn_indexPage_'+(i+1)); //type="button"
        btn_indexPage.setAttribute('value',i+1); //type="button"
        btn_indexPage.setAttribute('type','button'); //type="button"
        btn_indexPage.innerHTML=i+1;
        btn_indexPage.onclick=function(){
            var index=i;
            getOnePage_DiningReceipts(flag_admin,flag_type_diningReceipt,parseInt(this.value));
        };
        $('#div_data_navagation').append(btn_indexPage);
    }
    var div_data_navagation_html3='<button id="btn_nextPage">siguiente</button>';
    $('#div_data_navagation').append(div_data_navagation_html3);
    $('#btn_previousPage').click(function(){
        if(index_page>1){
            index_page=index_page-1;           
            getOnePage_DiningReceipts(flag_admin,flag_type_diningReceipt,index_page);
        }
    });
    $('#btn_nextPage').click(function(){
        if(index_page<number_page){
            index_page=index_page+1;           
            getOnePage_DiningReceipts(flag_admin,flag_type_diningReceipt,index_page);
        }
    });
}
var g_path;
function getDiningReceipts(path,flag_admin,flag_type_diningReceipt,timeStamp_filter) {
    console.log(timeStamp_filter);
    var url;
    g_path=path;
    if (flag_type_diningReceipt==1||flag_type_diningReceipt==2){
        if (flag_admin){
            url=path+"/Action/Action_DiningReceiptAction_getDiningReceipt_sum_list";
        }
        else {
            url=path+"/Action/Action_DiningReceiptAction_getDiningReceipt_sum_list_employee_account";
        }
        if (flag_type_diningReceipt==2){
            url=url+"_nodining_company"
        }
    }
    else if (flag_type_diningReceipt==0){
        if (flag_admin){
            url=path+"/Action/Action_DiningReceiptAction_getAll_list";
        }
        else {
            url=path+"/Action/Action_DiningReceiptAction_get_list_employee_account";
        }
    }
    $.ajax({
        //几个参数需要注意一下
        type: "POST",//方法类型
        // dataType: "json",//预期服务器返回的数据类型
        url: url ,//url
        data: {falg_allData:falg_allData,timeStamp_filter:timeStamp_filter},
        success: function (result) {
            list_diningReceipt=eval(result);
            initBynumberData_perPage_list_diningReceipt_filter();
            getPages(flag_admin,flag_type_diningReceipt);

        },
        error : function() {
            alert("网络异常！");
        }
    });
}
Array.prototype.remove=function(dx)
{
    if(isNaN(dx)||dx>this.length){return false;}
    for(var i=0,n=0;i<this.length;i++)
    {
        if(this[i]!=this[dx])
        {
            this[n++]=this[i]
        }
    }
    this.length-=1
};
function initAll_list_diningReceipt_filter() {
    list_diningReceipt_filter=[];
    for (var index_com = 0; index_com < list_diningReceipt.length; index_com++) {
        list_diningReceipt_filter[index_com]=list_diningReceipt[index_com];
    }
}
function initBynumberData_perPage_list_diningReceipt_filter() {
    list_diningReceipt_filter=[];
    for (var index_com = 0; index_com < numberData_perPage*max_number_page; index_com++) {
        if (index_com>=list_diningReceipt.length){
            break;
        }
        list_diningReceipt_filter[index_com]=list_diningReceipt[index_com];
    }
}
function filterDiningReceipt_dining_time_inSql(flag_admin,flag_type_diningReceipt) {
    var time_limited1=$('#dining_time_filter').val();
    // var time_limited2=$('#dining_time_filter2').val();
    var timeStamp_filter = new Date(time_limited1).getTime();
    getDiningReceipts(g_path,flag_admin,flag_type_diningReceipt,timeStamp_filter);
}
function filterDiningReceipt(flag_admin,flag_type_diningReceipt) {
    index_page=1;
    initBynumberData_perPage_list_diningReceipt_filter();
    getPages(flag_admin,flag_type_diningReceipt);
}
function filterDiningReceipt_andReQuerySql(flag_admin,flag_type_diningReceipt) {
    index_page=1;
    filterDiningReceipt_dining_time_inSql(flag_admin,flag_type_diningReceipt);
    // initBynumberData_perPage_list_diningReceipt_filter();
    getPages(flag_admin,flag_type_diningReceipt);
}
//按公司名筛选就餐信息
function filterDiningReceipt_dining_company() {
    var dining_company_filter = $('#dining_company_filter').val();
    for (var index_com = 0; index_com < list_diningReceipt_filter.length; index_com++) {
        if (list_diningReceipt_filter[index_com]['dining_company']!=null&&list_diningReceipt_filter[index_com]['dining_company'].search(dining_company_filter)==-1){
            list_diningReceipt_filter.remove(index_com);
            index_com=index_com-1;
        }
    }
}
//按就餐时间名筛选就餐信息
function filterDiningReceipt_dining_time() {
    var time_limited1=$('#dining_time_filter').val();
    // var time_limited2=$('#dining_time_filter2').val();
    var timeStamp_filter = new Date(time_limited1).getTime();
    // var timeStamp_filter2 = new Date(time_limited2).getTime();
    for (var index_com = 0; index_com < list_diningReceipt_filter.length; index_com++) {
        var timeStamp = new Date(list_diningReceipt_filter[index_com]['dining_time']).getTime();
        if (timeStamp<timeStamp_filter){
            list_diningReceipt_filter.remove(index_com);
            index_com=index_com-1;
        }
    }
}
//按就餐类型选就餐信息
function filterDiningReceipt_dining_type() {
    var dining_type_filter =  $('#dining_type_filter').val();
    for (var index_com = 0; index_com < list_diningReceipt_filter.length; index_com++) {
        if (list_diningReceipt_filter[index_com]['dining_type'].search(dining_type_filter)==-1){
            list_diningReceipt_filter.remove(index_com);
            index_com=index_com-1;
        }
    }
}